<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Regexp
 *
 * @author chaporgin_a
 */
class VA_Form_Validator_Regexp extends VA_Form_Validator {
  protected $expr = null;
  public $message = null;
  public function  __construct() {
    $this->errorMessages = array();
  }
  public function init($options){
    parent::init($options);
    $this->message = $this->getOption('message', 'Введенные данные неверны');
    $this->message = $this->getOption('expression', '');
  }
  protected function checkRegexp($value){
    $matches = array();
    if(!preg_match($this->expr, $value, $matches))
            return FALSE;
    return TRUE;
  }
  public function isValid($value) {
    if(!$this->checkRegexp($value)) {
      $this->errorMessages[] = $this->message;
      return FALSE;
    }
    return TRUE;
  }
  public function getHTMLTagAttributes() {return array();}
}

